<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">

<html lang="en">

<head>
  <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
  <title>LCOV - code analysis - /usr/include/boost/math/special_functions/next.hpp</title>
  <link rel="stylesheet" type="text/css" href="../../../../../gcov.css">
</head>

<body>

  <table width="100%" border=0 cellspacing=0 cellpadding=0>
    <tr><td class="title">LCOV - code coverage report</td></tr>
    <tr><td class="ruler"><img src="../../../../../glass.png" width=3 height=3 alt=""></td></tr>

    <tr>
      <td width="100%">
        <table cellpadding=1 border=0 width="100%">
          <tr>
            <td width="10%" class="headerItem">Current view:</td>
            <td width="35%" class="headerValue"><a href="../../../../../index.html">top level</a> - <a href="index.html">usr/include/boost/math/special_functions</a> - next.hpp<span style="font-size: 80%;"> (source / <a href="next.hpp.func-sort-c.html">functions</a>)</span></td>
            <td width="5%"></td>
            <td width="15%"></td>
            <td width="10%" class="headerCovTableHead">Hit</td>
            <td width="10%" class="headerCovTableHead">Total</td>
            <td width="15%" class="headerCovTableHead">Coverage</td>
          </tr>
          <tr>
            <td class="headerItem">Test:</td>
            <td class="headerValue">code analysis</td>
            <td></td>
            <td class="headerItem">Lines:</td>
            <td class="headerCovTableEntry">19</td>
            <td class="headerCovTableEntry">48</td>
            <td class="headerCovTableEntryLo">39.6 %</td>
          </tr>
          <tr>
            <td class="headerItem">Date:</td>
            <td class="headerValue">2020-09-11 22:50:33</td>
            <td></td>
            <td class="headerItem">Functions:</td>
            <td class="headerCovTableEntry">4</td>
            <td class="headerCovTableEntry">14</td>
            <td class="headerCovTableEntryLo">28.6 %</td>
          </tr>
          <tr>
            <td class="headerItem">Legend:</td>
            <td class="headerValueLeg">            Lines:
            <span class="coverLegendCov">hit</span>
            <span class="coverLegendNoCov">not hit</span>
</td>
            <td></td>
          </tr>
          <tr><td><img src="../../../../../glass.png" width=3 height=3 alt=""></td></tr>
        </table>
      </td>
    </tr>

    <tr><td class="ruler"><img src="../../../../../glass.png" width=3 height=3 alt=""></td></tr>
  </table>

  <table cellpadding=0 cellspacing=0 border=0>
    <tr>
      <td><br></td>
    </tr>
    <tr>
      <td>
<pre class="sourceHeading">          Line data    Source code</pre>
<pre class="source">
<a name="1"><span class="lineNum">       1 </span>            : //  (C) Copyright John Maddock 2008.</a>
<span class="lineNum">       2 </span>            : //  Use, modification and distribution are subject to the
<span class="lineNum">       3 </span>            : //  Boost Software License, Version 1.0. (See accompanying file
<span class="lineNum">       4 </span>            : //  LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
<span class="lineNum">       5 </span>            : 
<span class="lineNum">       6 </span>            : #ifndef BOOST_MATH_SPECIAL_NEXT_HPP
<span class="lineNum">       7 </span>            : #define BOOST_MATH_SPECIAL_NEXT_HPP
<span class="lineNum">       8 </span>            : 
<span class="lineNum">       9 </span>            : #ifdef _MSC_VER
<span class="lineNum">      10 </span>            : #pragma once
<span class="lineNum">      11 </span>            : #endif
<span class="lineNum">      12 </span>            : 
<span class="lineNum">      13 </span>            : #include &lt;boost/math/special_functions/math_fwd.hpp&gt;
<span class="lineNum">      14 </span>            : #include &lt;boost/math/policies/error_handling.hpp&gt;
<span class="lineNum">      15 </span>            : #include &lt;boost/math/special_functions/fpclassify.hpp&gt;
<span class="lineNum">      16 </span>            : #include &lt;boost/math/special_functions/sign.hpp&gt;
<span class="lineNum">      17 </span>            : #include &lt;boost/math/special_functions/trunc.hpp&gt;
<span class="lineNum">      18 </span>            : 
<span class="lineNum">      19 </span>            : #include &lt;float.h&gt;
<span class="lineNum">      20 </span>            : 
<span class="lineNum">      21 </span>            : #if !defined(_CRAYC) &amp;&amp; !defined(__CUDACC__) &amp;&amp; (!defined(__GNUC__) || (__GNUC__ &gt; 3) || ((__GNUC__ == 3) &amp;&amp; (__GNUC_MINOR__ &gt; 3)))
<span class="lineNum">      22 </span>            : #if (defined(_M_IX86_FP) &amp;&amp; (_M_IX86_FP &gt;= 2)) || defined(__SSE2__)
<span class="lineNum">      23 </span>            : #include &quot;xmmintrin.h&quot;
<span class="lineNum">      24 </span>            : #define BOOST_MATH_CHECK_SSE2
<span class="lineNum">      25 </span>            : #endif
<span class="lineNum">      26 </span>            : #endif
<span class="lineNum">      27 </span>            : 
<span class="lineNum">      28 </span>            : namespace boost{ namespace math{
<span class="lineNum">      29 </span>            : 
<span class="lineNum">      30 </span>            : namespace detail{
<a name="31"><span class="lineNum">      31 </span>            : </a>
<span class="lineNum">      32 </span>            : template &lt;class T&gt;
<span class="lineNum">      33 </span><span class="lineNoCov">          0 : inline T get_smallest_value(mpl::true_ const&amp;)</span>
<span class="lineNum">      34 </span>            : {
<span class="lineNum">      35 </span>            :    //
<span class="lineNum">      36 </span>            :    // numeric_limits lies about denorms being present - particularly
<span class="lineNum">      37 </span>            :    // when this can be turned on or off at runtime, as is the case
<span class="lineNum">      38 </span>            :    // when using the SSE2 registers in DAZ or FTZ mode.
<span class="lineNum">      39 </span>            :    //
<span class="lineNum">      40 </span><span class="lineNoCov">          0 :    static const T m = std::numeric_limits&lt;T&gt;::denorm_min();</span>
<span class="lineNum">      41 </span>            : #ifdef BOOST_MATH_CHECK_SSE2
<span class="lineNum">      42 </span><span class="lineNoCov">          0 :    return (_mm_getcsr() &amp; (_MM_FLUSH_ZERO_ON | 0x40)) ? tools::min_value&lt;T&gt;() : m;;</span>
<span class="lineNum">      43 </span>            : #else
<span class="lineNum">      44 </span>            :    return ((tools::min_value&lt;T&gt;() / 2) == 0) ? tools::min_value&lt;T&gt;() : m;
<span class="lineNum">      45 </span>            : #endif
<span class="lineNum">      46 </span>            : }
<span class="lineNum">      47 </span>            : 
<span class="lineNum">      48 </span>            : template &lt;class T&gt;
<span class="lineNum">      49 </span>            : inline T get_smallest_value(mpl::false_ const&amp;)
<span class="lineNum">      50 </span>            : {
<span class="lineNum">      51 </span>            :    return tools::min_value&lt;T&gt;();
<span class="lineNum">      52 </span>            : }
<span class="lineNum">      53 </span>            : 
<span class="lineNum">      54 </span>            : template &lt;class T&gt;
<span class="lineNum">      55 </span>            : inline T get_smallest_value()
<span class="lineNum">      56 </span>            : {
<span class="lineNum">      57 </span>            : #if defined(BOOST_MSVC) &amp;&amp; (BOOST_MSVC &lt;= 1310)
<span class="lineNum">      58 </span>            :    return get_smallest_value&lt;T&gt;(mpl::bool_&lt;std::numeric_limits&lt;T&gt;::is_specialized &amp;&amp; (std::numeric_limits&lt;T&gt;::has_denorm == 1)&gt;());
<span class="lineNum">      59 </span>            : #else
<span class="lineNum">      60 </span><span class="lineNoCov">          0 :    return get_smallest_value&lt;T&gt;(mpl::bool_&lt;std::numeric_limits&lt;T&gt;::is_specialized &amp;&amp; (std::numeric_limits&lt;T&gt;::has_denorm == std::denorm_present)&gt;());</span>
<span class="lineNum">      61 </span>            : #endif
<span class="lineNum">      62 </span>            : }
<span class="lineNum">      63 </span>            : 
<span class="lineNum">      64 </span>            : //
<span class="lineNum">      65 </span>            : // Returns the smallest value that won't generate denorms when
<span class="lineNum">      66 </span>            : // we calculate the value of the least-significant-bit:
<span class="lineNum">      67 </span>            : //
<span class="lineNum">      68 </span>            : template &lt;class T&gt;
<span class="lineNum">      69 </span>            : T get_min_shift_value();
<span class="lineNum">      70 </span>            : 
<span class="lineNum">      71 </span>            : template &lt;class T&gt;
<span class="lineNum">      72 </span>            : struct min_shift_initializer
<span class="lineNum">      73 </span>            : {
<span class="lineNum">      74 </span>            :    struct init
<span class="lineNum">      75 </span>            :    {
<span class="lineNum">      76 </span>            :       init()
<span class="lineNum">      77 </span>            :       {
<span class="lineNum">      78 </span>            :          do_init();
<span class="lineNum">      79 </span>            :       }
<span class="lineNum">      80 </span>            :       static void do_init()
<span class="lineNum">      81 </span>            :       {
<span class="lineNum">      82 </span><span class="lineCov">          2 :          get_min_shift_value&lt;T&gt;();</span>
<span class="lineNum">      83 </span>            :       }
<span class="lineNum">      84 </span>            :       void force_instantiate()const{}
<span class="lineNum">      85 </span>            :    };
<span class="lineNum">      86 </span>            :    static const init initializer;
<span class="lineNum">      87 </span>            :    static void force_instantiate()
<span class="lineNum">      88 </span>            :    {
<span class="lineNum">      89 </span>            :       initializer.force_instantiate();
<span class="lineNum">      90 </span>            :    }
<span class="lineNum">      91 </span>            : };
<span class="lineNum">      92 </span>            : 
<span class="lineNum">      93 </span>            : template &lt;class T&gt;
<span class="lineNum">      94 </span><span class="lineCov">          2 : const typename min_shift_initializer&lt;T&gt;::init min_shift_initializer&lt;T&gt;::initializer;</span>
<span class="lineNum">      95 </span>            : 
<a name="96"><span class="lineNum">      96 </span>            : </a>
<span class="lineNum">      97 </span>            : template &lt;class T&gt;
<span class="lineNum">      98 </span><span class="lineCov">         10 : inline T get_min_shift_value()</span>
<span class="lineNum">      99 </span>            : {
<span class="lineNum">     100 </span>            :    BOOST_MATH_STD_USING
<span class="lineNum">     101 </span><span class="lineCov">         10 :    static const T val = ldexp(tools::min_value&lt;T&gt;(), tools::digits&lt;T&gt;() + 1);</span>
<span class="lineNum">     102 </span>            :    min_shift_initializer&lt;T&gt;::force_instantiate();
<span class="lineNum">     103 </span>            : 
<span class="lineNum">     104 </span><span class="lineCov">         10 :    return val;</span>
<span class="lineNum">     105 </span>            : }
<a name="106"><span class="lineNum">     106 </span>            : </a>
<span class="lineNum">     107 </span>            : template &lt;class T, class Policy&gt;
<span class="lineNum">     108 </span><span class="lineCov">          8 : T float_next_imp(const T&amp; val, const Policy&amp; pol)</span>
<span class="lineNum">     109 </span>            : {
<span class="lineNum">     110 </span>            :    BOOST_MATH_STD_USING
<span class="lineNum">     111 </span>            :    int expon;
<span class="lineNum">     112 </span>            :    static const char* function = &quot;float_next&lt;%1%&gt;(%1%)&quot;;
<span class="lineNum">     113 </span>            : 
<span class="lineNum">     114 </span><span class="lineCov">          8 :    int fpclass = (boost::math::fpclassify)(val);</span>
<span class="lineNum">     115 </span>            : 
<span class="lineNum">     116 </span><span class="lineCov">          8 :    if((fpclass == (int)FP_NAN) || (fpclass == (int)FP_INFINITE))</span>
<span class="lineNum">     117 </span>            :    {
<span class="lineNum">     118 </span><span class="lineNoCov">          0 :       if(val &lt; 0)</span>
<span class="lineNum">     119 </span>            :          return -tools::max_value&lt;T&gt;();
<span class="lineNum">     120 </span><span class="lineNoCov">          0 :       return policies::raise_domain_error&lt;T&gt;(</span>
<span class="lineNum">     121 </span>            :          function,
<span class="lineNum">     122 </span>            :          &quot;Argument must be finite, but got %1%&quot;, val, pol);
<span class="lineNum">     123 </span>            :    }
<span class="lineNum">     124 </span>            : 
<span class="lineNum">     125 </span><span class="lineCov">          8 :    if(val &gt;= tools::max_value&lt;T&gt;())</span>
<span class="lineNum">     126 </span><span class="lineNoCov">          0 :       return policies::raise_overflow_error&lt;T&gt;(function, 0, pol);</span>
<span class="lineNum">     127 </span>            : 
<span class="lineNum">     128 </span><span class="lineCov">          8 :    if(val == 0)</span>
<span class="lineNum">     129 </span>            :       return detail::get_smallest_value&lt;T&gt;();
<span class="lineNum">     130 </span>            : 
<span class="lineNum">     131 </span><span class="lineCov">          8 :    if((fpclass != (int)FP_SUBNORMAL) &amp;&amp; (fpclass != (int)FP_ZERO) &amp;&amp; (fabs(val) &lt; detail::get_min_shift_value&lt;T&gt;()) &amp;&amp; (val != -tools::min_value&lt;T&gt;()))</span>
<span class="lineNum">     132 </span>            :    {
<span class="lineNum">     133 </span>            :       //
<span class="lineNum">     134 </span>            :       // Special case: if the value of the least significant bit is a denorm, and the result
<span class="lineNum">     135 </span>            :       // would not be a denorm, then shift the input, increment, and shift back.
<span class="lineNum">     136 </span>            :       // This avoids issues with the Intel SSE2 registers when the FTZ or DAZ flags are set.
<span class="lineNum">     137 </span>            :       //
<span class="lineNum">     138 </span><span class="lineNoCov">          0 :       return ldexp(float_next(T(ldexp(val, 2 * tools::digits&lt;T&gt;())), pol), -2 * tools::digits&lt;T&gt;());</span>
<span class="lineNum">     139 </span>            :    }
<span class="lineNum">     140 </span>            : 
<span class="lineNum">     141 </span><span class="lineCov">         16 :    if(-0.5f == frexp(val, &amp;expon))</span>
<span class="lineNum">     142 </span><span class="lineNoCov">          0 :       --expon; // reduce exponent when val is a power of two, and negative.</span>
<span class="lineNum">     143 </span><span class="lineCov">          8 :    T diff = ldexp(T(1), expon - tools::digits&lt;T&gt;());</span>
<span class="lineNum">     144 </span><span class="lineCov">          8 :    if(diff == 0)</span>
<span class="lineNum">     145 </span>            :       diff = detail::get_smallest_value&lt;T&gt;();
<span class="lineNum">     146 </span><span class="lineCov">          8 :    return val + diff;</span>
<span class="lineNum">     147 </span>            : }
<span class="lineNum">     148 </span>            : 
<span class="lineNum">     149 </span>            : }
<a name="150"><span class="lineNum">     150 </span>            : </a>
<span class="lineNum">     151 </span>            : template &lt;class T, class Policy&gt;
<span class="lineNum">     152 </span><span class="lineNoCov">          0 : inline typename tools::promote_args&lt;T&gt;::type float_next(const T&amp; val, const Policy&amp; pol)</span>
<span class="lineNum">     153 </span>            : {
<span class="lineNum">     154 </span>            :    typedef typename tools::promote_args&lt;T&gt;::type result_type;
<span class="lineNum">     155 </span><span class="lineCov">          8 :    return detail::float_next_imp(static_cast&lt;result_type&gt;(val), pol);</span>
<span class="lineNum">     156 </span>            : }
<span class="lineNum">     157 </span>            : 
<span class="lineNum">     158 </span>            : #if 0 //def BOOST_MSVC
<span class="lineNum">     159 </span>            : //
<span class="lineNum">     160 </span>            : // We used to use ::_nextafter here, but doing so fails when using
<span class="lineNum">     161 </span>            : // the SSE2 registers if the FTZ or DAZ flags are set, so use our own
<span class="lineNum">     162 </span>            : // - albeit slower - code instead as at least that gives the correct answer.
<span class="lineNum">     163 </span>            : //
<span class="lineNum">     164 </span>            : template &lt;class Policy&gt;
<span class="lineNum">     165 </span>            : inline double float_next(const double&amp; val, const Policy&amp; pol)
<span class="lineNum">     166 </span>            : {
<span class="lineNum">     167 </span>            :    static const char* function = &quot;float_next&lt;%1%&gt;(%1%)&quot;;
<span class="lineNum">     168 </span>            : 
<span class="lineNum">     169 </span>            :    if(!(boost::math::isfinite)(val) &amp;&amp; (val &gt; 0))
<span class="lineNum">     170 </span>            :       return policies::raise_domain_error&lt;double&gt;(
<span class="lineNum">     171 </span>            :          function,
<span class="lineNum">     172 </span>            :          &quot;Argument must be finite, but got %1%&quot;, val, pol);
<span class="lineNum">     173 </span>            : 
<span class="lineNum">     174 </span>            :    if(val &gt;= tools::max_value&lt;double&gt;())
<span class="lineNum">     175 </span>            :       return policies::raise_overflow_error&lt;double&gt;(function, 0, pol);
<span class="lineNum">     176 </span>            : 
<span class="lineNum">     177 </span>            :    return ::_nextafter(val, tools::max_value&lt;double&gt;());
<span class="lineNum">     178 </span>            : }
<span class="lineNum">     179 </span>            : #endif
<span class="lineNum">     180 </span>            : 
<span class="lineNum">     181 </span>            : template &lt;class T&gt;
<span class="lineNum">     182 </span>            : inline typename tools::promote_args&lt;T&gt;::type float_next(const T&amp; val)
<span class="lineNum">     183 </span>            : {
<span class="lineNum">     184 </span>            :    return float_next(val, policies::policy&lt;&gt;());
<span class="lineNum">     185 </span>            : }
<span class="lineNum">     186 </span>            : 
<span class="lineNum">     187 </span>            : namespace detail{
<a name="188"><span class="lineNum">     188 </span>            : </a>
<span class="lineNum">     189 </span>            : template &lt;class T, class Policy&gt;
<span class="lineNum">     190 </span><span class="lineNoCov">          0 : T float_prior_imp(const T&amp; val, const Policy&amp; pol)</span>
<span class="lineNum">     191 </span>            : {
<span class="lineNum">     192 </span>            :    BOOST_MATH_STD_USING
<span class="lineNum">     193 </span>            :    int expon;
<span class="lineNum">     194 </span>            :    static const char* function = &quot;float_prior&lt;%1%&gt;(%1%)&quot;;
<span class="lineNum">     195 </span>            : 
<span class="lineNum">     196 </span><span class="lineNoCov">          0 :    int fpclass = (boost::math::fpclassify)(val);</span>
<span class="lineNum">     197 </span>            : 
<span class="lineNum">     198 </span><span class="lineNoCov">          0 :    if((fpclass == (int)FP_NAN) || (fpclass == (int)FP_INFINITE))</span>
<span class="lineNum">     199 </span>            :    {
<span class="lineNum">     200 </span><span class="lineNoCov">          0 :       if(val &gt; 0)</span>
<span class="lineNum">     201 </span>            :          return tools::max_value&lt;T&gt;();
<span class="lineNum">     202 </span><span class="lineNoCov">          0 :       return policies::raise_domain_error&lt;T&gt;(</span>
<span class="lineNum">     203 </span>            :          function,
<span class="lineNum">     204 </span>            :          &quot;Argument must be finite, but got %1%&quot;, val, pol);
<span class="lineNum">     205 </span>            :    }
<span class="lineNum">     206 </span>            : 
<span class="lineNum">     207 </span><span class="lineNoCov">          0 :    if(val &lt;= -tools::max_value&lt;T&gt;())</span>
<span class="lineNum">     208 </span><span class="lineNoCov">          0 :       return -policies::raise_overflow_error&lt;T&gt;(function, 0, pol);</span>
<span class="lineNum">     209 </span>            : 
<span class="lineNum">     210 </span><span class="lineNoCov">          0 :    if(val == 0)</span>
<span class="lineNum">     211 </span><span class="lineNoCov">          0 :       return -detail::get_smallest_value&lt;T&gt;();</span>
<span class="lineNum">     212 </span>            : 
<span class="lineNum">     213 </span><span class="lineNoCov">          0 :    if((fpclass != (int)FP_SUBNORMAL) &amp;&amp; (fpclass != (int)FP_ZERO) &amp;&amp; (fabs(val) &lt; detail::get_min_shift_value&lt;T&gt;()) &amp;&amp; (val != tools::min_value&lt;T&gt;()))</span>
<span class="lineNum">     214 </span>            :    {
<span class="lineNum">     215 </span>            :       //
<span class="lineNum">     216 </span>            :       // Special case: if the value of the least significant bit is a denorm, and the result
<span class="lineNum">     217 </span>            :       // would not be a denorm, then shift the input, increment, and shift back.
<span class="lineNum">     218 </span>            :       // This avoids issues with the Intel SSE2 registers when the FTZ or DAZ flags are set.
<span class="lineNum">     219 </span>            :       //
<span class="lineNum">     220 </span><span class="lineNoCov">          0 :       return ldexp(float_prior(T(ldexp(val, 2 * tools::digits&lt;T&gt;())), pol), -2 * tools::digits&lt;T&gt;());</span>
<span class="lineNum">     221 </span>            :    }
<span class="lineNum">     222 </span>            : 
<span class="lineNum">     223 </span><span class="lineNoCov">          0 :    T remain = frexp(val, &amp;expon);</span>
<span class="lineNum">     224 </span><span class="lineNoCov">          0 :    if(remain == 0.5)</span>
<span class="lineNum">     225 </span><span class="lineNoCov">          0 :       --expon; // when val is a power of two we must reduce the exponent</span>
<span class="lineNum">     226 </span><span class="lineNoCov">          0 :    T diff = ldexp(T(1), expon - tools::digits&lt;T&gt;());</span>
<span class="lineNum">     227 </span><span class="lineNoCov">          0 :    if(diff == 0)</span>
<span class="lineNum">     228 </span>            :       diff = detail::get_smallest_value&lt;T&gt;();
<span class="lineNum">     229 </span><span class="lineNoCov">          0 :    return val - diff;</span>
<span class="lineNum">     230 </span>            : }
<span class="lineNum">     231 </span>            : 
<span class="lineNum">     232 </span>            : }
<a name="233"><span class="lineNum">     233 </span>            : </a>
<span class="lineNum">     234 </span>            : template &lt;class T, class Policy&gt;
<span class="lineNum">     235 </span><span class="lineNoCov">          0 : inline typename tools::promote_args&lt;T&gt;::type float_prior(const T&amp; val, const Policy&amp; pol)</span>
<span class="lineNum">     236 </span>            : {
<span class="lineNum">     237 </span>            :    typedef typename tools::promote_args&lt;T&gt;::type result_type;
<span class="lineNum">     238 </span><span class="lineNoCov">          0 :    return detail::float_prior_imp(static_cast&lt;result_type&gt;(val), pol);</span>
<span class="lineNum">     239 </span>            : }
<span class="lineNum">     240 </span>            : 
<span class="lineNum">     241 </span>            : #if 0 //def BOOST_MSVC
<span class="lineNum">     242 </span>            : //
<span class="lineNum">     243 </span>            : // We used to use ::_nextafter here, but doing so fails when using
<span class="lineNum">     244 </span>            : // the SSE2 registers if the FTZ or DAZ flags are set, so use our own
<span class="lineNum">     245 </span>            : // - albeit slower - code instead as at least that gives the correct answer.
<span class="lineNum">     246 </span>            : //
<span class="lineNum">     247 </span>            : template &lt;class Policy&gt;
<span class="lineNum">     248 </span>            : inline double float_prior(const double&amp; val, const Policy&amp; pol)
<span class="lineNum">     249 </span>            : {
<span class="lineNum">     250 </span>            :    static const char* function = &quot;float_prior&lt;%1%&gt;(%1%)&quot;;
<span class="lineNum">     251 </span>            : 
<span class="lineNum">     252 </span>            :    if(!(boost::math::isfinite)(val) &amp;&amp; (val &lt; 0))
<span class="lineNum">     253 </span>            :       return policies::raise_domain_error&lt;double&gt;(
<span class="lineNum">     254 </span>            :          function,
<span class="lineNum">     255 </span>            :          &quot;Argument must be finite, but got %1%&quot;, val, pol);
<span class="lineNum">     256 </span>            : 
<span class="lineNum">     257 </span>            :    if(val &lt;= -tools::max_value&lt;double&gt;())
<span class="lineNum">     258 </span>            :       return -policies::raise_overflow_error&lt;double&gt;(function, 0, pol);
<span class="lineNum">     259 </span>            : 
<span class="lineNum">     260 </span>            :    return ::_nextafter(val, -tools::max_value&lt;double&gt;());
<span class="lineNum">     261 </span>            : }
<span class="lineNum">     262 </span>            : #endif
<span class="lineNum">     263 </span>            : 
<span class="lineNum">     264 </span>            : template &lt;class T&gt;
<span class="lineNum">     265 </span>            : inline typename tools::promote_args&lt;T&gt;::type float_prior(const T&amp; val)
<span class="lineNum">     266 </span>            : {
<span class="lineNum">     267 </span>            :    return float_prior(val, policies::policy&lt;&gt;());
<span class="lineNum">     268 </span>            : }
<a name="269"><span class="lineNum">     269 </span>            : </a>
<span class="lineNum">     270 </span>            : template &lt;class T, class U, class Policy&gt;
<span class="lineNum">     271 </span><span class="lineCov">          8 : inline typename tools::promote_args&lt;T, U&gt;::type nextafter(const T&amp; val, const U&amp; direction, const Policy&amp; pol)</span>
<span class="lineNum">     272 </span>            : {
<span class="lineNum">     273 </span>            :    typedef typename tools::promote_args&lt;T, U&gt;::type result_type;
<span class="lineNum">     274 </span><span class="lineCov">         16 :    return val &lt; direction ? boost::math::float_next&lt;result_type&gt;(val, pol) : val == direction ? val : boost::math::float_prior&lt;result_type&gt;(val, pol);</span>
<span class="lineNum">     275 </span>            : }
<span class="lineNum">     276 </span>            : 
<span class="lineNum">     277 </span>            : template &lt;class T, class U&gt;
<span class="lineNum">     278 </span>            : inline typename tools::promote_args&lt;T, U&gt;::type nextafter(const T&amp; val, const U&amp; direction)
<span class="lineNum">     279 </span>            : {
<span class="lineNum">     280 </span><span class="lineCov">          8 :    return nextafter(val, direction, policies::policy&lt;&gt;());</span>
<span class="lineNum">     281 </span>            : }
<span class="lineNum">     282 </span>            : 
<span class="lineNum">     283 </span>            : namespace detail{
<span class="lineNum">     284 </span>            : 
<span class="lineNum">     285 </span>            : template &lt;class T, class Policy&gt;
<span class="lineNum">     286 </span>            : T float_distance_imp(const T&amp; a, const T&amp; b, const Policy&amp; pol)
<span class="lineNum">     287 </span>            : {
<span class="lineNum">     288 </span>            :    BOOST_MATH_STD_USING
<span class="lineNum">     289 </span>            :    //
<span class="lineNum">     290 </span>            :    // Error handling:
<span class="lineNum">     291 </span>            :    //
<span class="lineNum">     292 </span>            :    static const char* function = &quot;float_distance&lt;%1%&gt;(%1%, %1%)&quot;;
<span class="lineNum">     293 </span>            :    if(!(boost::math::isfinite)(a))
<span class="lineNum">     294 </span>            :       return policies::raise_domain_error&lt;T&gt;(
<span class="lineNum">     295 </span>            :          function,
<span class="lineNum">     296 </span>            :          &quot;Argument a must be finite, but got %1%&quot;, a, pol);
<span class="lineNum">     297 </span>            :    if(!(boost::math::isfinite)(b))
<span class="lineNum">     298 </span>            :       return policies::raise_domain_error&lt;T&gt;(
<span class="lineNum">     299 </span>            :          function,
<span class="lineNum">     300 </span>            :          &quot;Argument b must be finite, but got %1%&quot;, b, pol);
<span class="lineNum">     301 </span>            :    //
<span class="lineNum">     302 </span>            :    // Special cases:
<span class="lineNum">     303 </span>            :    //
<span class="lineNum">     304 </span>            :    if(a &gt; b)
<span class="lineNum">     305 </span>            :       return -float_distance(b, a, pol);
<span class="lineNum">     306 </span>            :    if(a == b)
<span class="lineNum">     307 </span>            :       return 0;
<span class="lineNum">     308 </span>            :    if(a == 0)
<span class="lineNum">     309 </span>            :       return 1 + fabs(float_distance(static_cast&lt;T&gt;((b &lt; 0) ? T(-detail::get_smallest_value&lt;T&gt;()) : detail::get_smallest_value&lt;T&gt;()), b, pol));
<span class="lineNum">     310 </span>            :    if(b == 0)
<span class="lineNum">     311 </span>            :       return 1 + fabs(float_distance(static_cast&lt;T&gt;((a &lt; 0) ? T(-detail::get_smallest_value&lt;T&gt;()) : detail::get_smallest_value&lt;T&gt;()), a, pol));
<span class="lineNum">     312 </span>            :    if(boost::math::sign(a) != boost::math::sign(b))
<span class="lineNum">     313 </span>            :       return 2 + fabs(float_distance(static_cast&lt;T&gt;((b &lt; 0) ? T(-detail::get_smallest_value&lt;T&gt;()) : detail::get_smallest_value&lt;T&gt;()), b, pol))
<span class="lineNum">     314 </span>            :          + fabs(float_distance(static_cast&lt;T&gt;((a &lt; 0) ? T(-detail::get_smallest_value&lt;T&gt;()) : detail::get_smallest_value&lt;T&gt;()), a, pol));
<span class="lineNum">     315 </span>            :    //
<span class="lineNum">     316 </span>            :    // By the time we get here, both a and b must have the same sign, we want
<span class="lineNum">     317 </span>            :    // b &gt; a and both postive for the following logic:
<span class="lineNum">     318 </span>            :    //
<span class="lineNum">     319 </span>            :    if(a &lt; 0)
<span class="lineNum">     320 </span>            :       return float_distance(static_cast&lt;T&gt;(-b), static_cast&lt;T&gt;(-a), pol);
<span class="lineNum">     321 </span>            : 
<span class="lineNum">     322 </span>            :    BOOST_ASSERT(a &gt;= 0);
<span class="lineNum">     323 </span>            :    BOOST_ASSERT(b &gt;= a);
<span class="lineNum">     324 </span>            : 
<span class="lineNum">     325 </span>            :    int expon;
<span class="lineNum">     326 </span>            :    //
<span class="lineNum">     327 </span>            :    // Note that if a is a denorm then the usual formula fails
<span class="lineNum">     328 </span>            :    // because we actually have fewer than tools::digits&lt;T&gt;()
<span class="lineNum">     329 </span>            :    // significant bits in the representation:
<span class="lineNum">     330 </span>            :    //
<span class="lineNum">     331 </span>            :    frexp(((boost::math::fpclassify)(a) == (int)FP_SUBNORMAL) ? tools::min_value&lt;T&gt;() : a, &amp;expon);
<span class="lineNum">     332 </span>            :    T upper = ldexp(T(1), expon);
<span class="lineNum">     333 </span>            :    T result = 0;
<span class="lineNum">     334 </span>            :    expon = tools::digits&lt;T&gt;() - expon;
<span class="lineNum">     335 </span>            :    //
<span class="lineNum">     336 </span>            :    // If b is greater than upper, then we *must* split the calculation
<span class="lineNum">     337 </span>            :    // as the size of the ULP changes with each order of magnitude change:
<span class="lineNum">     338 </span>            :    //
<span class="lineNum">     339 </span>            :    if(b &gt; upper)
<span class="lineNum">     340 </span>            :    {
<span class="lineNum">     341 </span>            :       result = float_distance(upper, b);
<span class="lineNum">     342 </span>            :    }
<span class="lineNum">     343 </span>            :    //
<span class="lineNum">     344 </span>            :    // Use compensated double-double addition to avoid rounding
<span class="lineNum">     345 </span>            :    // errors in the subtraction:
<span class="lineNum">     346 </span>            :    //
<span class="lineNum">     347 </span>            :    T mb, x, y, z;
<span class="lineNum">     348 </span>            :    if(((boost::math::fpclassify)(a) == (int)FP_SUBNORMAL) || (b - a &lt; tools::min_value&lt;T&gt;()))
<span class="lineNum">     349 </span>            :    {
<span class="lineNum">     350 </span>            :       //
<span class="lineNum">     351 </span>            :       // Special case - either one end of the range is a denormal, or else the difference is.
<span class="lineNum">     352 </span>            :       // The regular code will fail if we're using the SSE2 registers on Intel and either
<span class="lineNum">     353 </span>            :       // the FTZ or DAZ flags are set.
<span class="lineNum">     354 </span>            :       //
<span class="lineNum">     355 </span>            :       T a2 = ldexp(a, tools::digits&lt;T&gt;());
<span class="lineNum">     356 </span>            :       T b2 = ldexp(b, tools::digits&lt;T&gt;());
<span class="lineNum">     357 </span>            :       mb = -(std::min)(T(ldexp(upper, tools::digits&lt;T&gt;())), b2);
<span class="lineNum">     358 </span>            :       x = a2 + mb;
<span class="lineNum">     359 </span>            :       z = x - a2;
<span class="lineNum">     360 </span>            :       y = (a2 - (x - z)) + (mb - z);
<span class="lineNum">     361 </span>            : 
<span class="lineNum">     362 </span>            :       expon -= tools::digits&lt;T&gt;();
<span class="lineNum">     363 </span>            :    }
<span class="lineNum">     364 </span>            :    else
<span class="lineNum">     365 </span>            :    {
<span class="lineNum">     366 </span>            :       mb = -(std::min)(upper, b);
<span class="lineNum">     367 </span>            :       x = a + mb;
<span class="lineNum">     368 </span>            :       z = x - a;
<span class="lineNum">     369 </span>            :       y = (a - (x - z)) + (mb - z);
<span class="lineNum">     370 </span>            :    }
<span class="lineNum">     371 </span>            :    if(x &lt; 0)
<span class="lineNum">     372 </span>            :    {
<span class="lineNum">     373 </span>            :       x = -x;
<span class="lineNum">     374 </span>            :       y = -y;
<span class="lineNum">     375 </span>            :    }
<span class="lineNum">     376 </span>            :    result += ldexp(x, expon) + ldexp(y, expon);
<span class="lineNum">     377 </span>            :    //
<span class="lineNum">     378 </span>            :    // Result must be an integer:
<span class="lineNum">     379 </span>            :    //
<span class="lineNum">     380 </span>            :    BOOST_ASSERT(result == floor(result));
<span class="lineNum">     381 </span>            :    return result;
<span class="lineNum">     382 </span>            : }
<span class="lineNum">     383 </span>            : 
<span class="lineNum">     384 </span>            : }
<span class="lineNum">     385 </span>            : 
<span class="lineNum">     386 </span>            : template &lt;class T, class U, class Policy&gt;
<span class="lineNum">     387 </span>            : inline typename tools::promote_args&lt;T, U&gt;::type float_distance(const T&amp; a, const U&amp; b, const Policy&amp; pol)
<span class="lineNum">     388 </span>            : {
<span class="lineNum">     389 </span>            :    typedef typename tools::promote_args&lt;T, U&gt;::type result_type;
<span class="lineNum">     390 </span>            :    return detail::float_distance_imp(static_cast&lt;result_type&gt;(a), static_cast&lt;result_type&gt;(b), pol);
<span class="lineNum">     391 </span>            : }
<span class="lineNum">     392 </span>            : 
<span class="lineNum">     393 </span>            : template &lt;class T, class U&gt;
<span class="lineNum">     394 </span>            : typename tools::promote_args&lt;T, U&gt;::type float_distance(const T&amp; a, const U&amp; b)
<span class="lineNum">     395 </span>            : {
<span class="lineNum">     396 </span>            :    return boost::math::float_distance(a, b, policies::policy&lt;&gt;());
<span class="lineNum">     397 </span>            : }
<span class="lineNum">     398 </span>            : 
<span class="lineNum">     399 </span>            : namespace detail{
<span class="lineNum">     400 </span>            : 
<span class="lineNum">     401 </span>            : template &lt;class T, class Policy&gt;
<span class="lineNum">     402 </span>            : T float_advance_imp(T val, int distance, const Policy&amp; pol)
<span class="lineNum">     403 </span>            : {
<span class="lineNum">     404 </span>            :    BOOST_MATH_STD_USING
<span class="lineNum">     405 </span>            :    //
<span class="lineNum">     406 </span>            :    // Error handling:
<span class="lineNum">     407 </span>            :    //
<span class="lineNum">     408 </span>            :    static const char* function = &quot;float_advance&lt;%1%&gt;(%1%, int)&quot;;
<span class="lineNum">     409 </span>            : 
<span class="lineNum">     410 </span>            :    int fpclass = (boost::math::fpclassify)(val);
<span class="lineNum">     411 </span>            : 
<span class="lineNum">     412 </span>            :    if((fpclass == (int)FP_NAN) || (fpclass == (int)FP_INFINITE))
<span class="lineNum">     413 </span>            :       return policies::raise_domain_error&lt;T&gt;(
<span class="lineNum">     414 </span>            :          function,
<span class="lineNum">     415 </span>            :          &quot;Argument val must be finite, but got %1%&quot;, val, pol);
<span class="lineNum">     416 </span>            : 
<span class="lineNum">     417 </span>            :    if(val &lt; 0)
<span class="lineNum">     418 </span>            :       return -float_advance(-val, -distance, pol);
<span class="lineNum">     419 </span>            :    if(distance == 0)
<span class="lineNum">     420 </span>            :       return val;
<span class="lineNum">     421 </span>            :    if(distance == 1)
<span class="lineNum">     422 </span>            :       return float_next(val, pol);
<span class="lineNum">     423 </span>            :    if(distance == -1)
<span class="lineNum">     424 </span>            :       return float_prior(val, pol);
<span class="lineNum">     425 </span>            : 
<span class="lineNum">     426 </span>            :    if(fabs(val) &lt; detail::get_min_shift_value&lt;T&gt;())
<span class="lineNum">     427 </span>            :    {
<span class="lineNum">     428 </span>            :       //
<span class="lineNum">     429 </span>            :       // Special case: if the value of the least significant bit is a denorm,
<span class="lineNum">     430 </span>            :       // implement in terms of float_next/float_prior.
<span class="lineNum">     431 </span>            :       // This avoids issues with the Intel SSE2 registers when the FTZ or DAZ flags are set.
<span class="lineNum">     432 </span>            :       //
<span class="lineNum">     433 </span>            :       if(distance &gt; 0)
<span class="lineNum">     434 </span>            :       {
<span class="lineNum">     435 </span>            :          do{ val = float_next(val, pol); } while(--distance);
<span class="lineNum">     436 </span>            :       }
<span class="lineNum">     437 </span>            :       else
<span class="lineNum">     438 </span>            :       {
<span class="lineNum">     439 </span>            :          do{ val = float_prior(val, pol); } while(++distance);
<span class="lineNum">     440 </span>            :       }
<span class="lineNum">     441 </span>            :       return val;
<span class="lineNum">     442 </span>            :    }
<span class="lineNum">     443 </span>            : 
<span class="lineNum">     444 </span>            :    int expon;
<span class="lineNum">     445 </span>            :    frexp(val, &amp;expon);
<span class="lineNum">     446 </span>            :    T limit = ldexp((distance &lt; 0 ? T(0.5f) : T(1)), expon);
<span class="lineNum">     447 </span>            :    if(val &lt;= tools::min_value&lt;T&gt;())
<span class="lineNum">     448 </span>            :    {
<span class="lineNum">     449 </span>            :       limit = sign(T(distance)) * tools::min_value&lt;T&gt;();
<span class="lineNum">     450 </span>            :    }
<span class="lineNum">     451 </span>            :    T limit_distance = float_distance(val, limit);
<span class="lineNum">     452 </span>            :    while(fabs(limit_distance) &lt; abs(distance))
<span class="lineNum">     453 </span>            :    {
<span class="lineNum">     454 </span>            :       distance -= itrunc(limit_distance);
<span class="lineNum">     455 </span>            :       val = limit;
<span class="lineNum">     456 </span>            :       if(distance &lt; 0)
<span class="lineNum">     457 </span>            :       {
<span class="lineNum">     458 </span>            :          limit /= 2;
<span class="lineNum">     459 </span>            :          expon--;
<span class="lineNum">     460 </span>            :       }
<span class="lineNum">     461 </span>            :       else
<span class="lineNum">     462 </span>            :       {
<span class="lineNum">     463 </span>            :          limit *= 2;
<span class="lineNum">     464 </span>            :          expon++;
<span class="lineNum">     465 </span>            :       }
<span class="lineNum">     466 </span>            :       limit_distance = float_distance(val, limit);
<span class="lineNum">     467 </span>            :       if(distance &amp;&amp; (limit_distance == 0))
<span class="lineNum">     468 </span>            :       {
<span class="lineNum">     469 </span>            :          return policies::raise_evaluation_error&lt;T&gt;(function, &quot;Internal logic failed while trying to increment floating point value %1%: most likely your FPU is in non-IEEE conforming mode.&quot;, val, pol);
<span class="lineNum">     470 </span>            :       }
<span class="lineNum">     471 </span>            :    }
<span class="lineNum">     472 </span>            :    if((0.5f == frexp(val, &amp;expon)) &amp;&amp; (distance &lt; 0))
<span class="lineNum">     473 </span>            :       --expon;
<span class="lineNum">     474 </span>            :    T diff = 0;
<span class="lineNum">     475 </span>            :    if(val != 0)
<span class="lineNum">     476 </span>            :       diff = distance * ldexp(T(1), expon - tools::digits&lt;T&gt;());
<span class="lineNum">     477 </span>            :    if(diff == 0)
<span class="lineNum">     478 </span>            :       diff = distance * detail::get_smallest_value&lt;T&gt;();
<span class="lineNum">     479 </span>            :    return val += diff;
<span class="lineNum">     480 </span>            : }
<span class="lineNum">     481 </span>            : 
<span class="lineNum">     482 </span>            : }
<span class="lineNum">     483 </span>            : 
<span class="lineNum">     484 </span>            : template &lt;class T, class Policy&gt;
<span class="lineNum">     485 </span>            : inline typename tools::promote_args&lt;T&gt;::type float_advance(T val, int distance, const Policy&amp; pol)
<span class="lineNum">     486 </span>            : {
<span class="lineNum">     487 </span>            :    typedef typename tools::promote_args&lt;T&gt;::type result_type;
<span class="lineNum">     488 </span>            :    return detail::float_advance_imp(static_cast&lt;result_type&gt;(val), distance, pol);
<span class="lineNum">     489 </span>            : }
<span class="lineNum">     490 </span>            : 
<span class="lineNum">     491 </span>            : template &lt;class T&gt;
<span class="lineNum">     492 </span>            : inline typename tools::promote_args&lt;T&gt;::type float_advance(const T&amp; val, int distance)
<span class="lineNum">     493 </span>            : {
<span class="lineNum">     494 </span>            :    return boost::math::float_advance(val, distance, policies::policy&lt;&gt;());
<span class="lineNum">     495 </span>            : }
<span class="lineNum">     496 </span>            : 
<span class="lineNum">     497 </span>            : }} // namespaces
<span class="lineNum">     498 </span>            : 
<span class="lineNum">     499 </span>            : #endif // BOOST_MATH_SPECIAL_NEXT_HPP
<span class="lineNum">     500 </span>            : 
</pre>
      </td>
    </tr>
  </table>
  <br>

  <table width="100%" border=0 cellspacing=0 cellpadding=0>
    <tr><td class="ruler"><img src="../../../../../glass.png" width=3 height=3 alt=""></td></tr>
    <tr><td class="versionInfo">Generated by: <a href="http://ltp.sourceforge.net/coverage/lcov.php" target="_parent">LCOV version 1.12</a></td></tr>
  </table>
  <br>

</body>
</html>
